//
//  SecondVC.m
//  Logistics
//
//  Created by 恩州科技 on 2018/8/4.
//  Copyright © 2018年 puyue.com. All rights reserved.
//

#import "SecondVC.h"
#import "VehicleTVCell.h"
#import "VehicleQueryVC.h"
#import "VehicleDetailsVC.h"
@interface SecondVC ()<UITableViewDelegate,UITableViewDataSource,VehicleCellDelegate>
@property (nonatomic,strong) UIButton * disButton;
@property (nonatomic,weak)UIButton *selectedBtn;//记录选中状态的按钮
@property (nonatomic,strong) UIView *viewGray;//滑动线
@property (nonatomic,strong) UITableView * vehicleTV;
@property (nonatomic,strong) UIView *headView;
@property (nonatomic,strong) UILabel *placeLabale;//起始地
@property (nonatomic,strong) UILabel *destinationaLbale;//目的地
@property (nonatomic,strong) UILabel *specificationLabale;//规格
@end
@implementation SecondVC
-(UITableView *)vehicleTV{
    if (!_vehicleTV) {
        _vehicleTV = [[UITableView alloc]initWithFrame:CGRectMake(0,  self.viewGray.bottom + 1, kMainScreen_width , kMainScreen_height - kMainTopHeight - GTFixHeightFlaot(37) - self.disButton.height - 4) style:UITableViewStyleGrouped];
        _vehicleTV.backgroundColor = WGColor;
        _vehicleTV.showsVerticalScrollIndicator = NO;
        _vehicleTV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _vehicleTV.dataSource = self;
        _vehicleTV.delegate = self;
    }
    return _vehicleTV;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    self.navTitle = @"车库";
    [self.navRightBtn setImage:[UIImage imageNamed:@"Search"] forState:0];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
-(void)right_button_event:(UIButton *)sender {
    VehicleQueryVC * vc = [VehicleQueryVC new];
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)createUI {
    NSArray *arr = @[@"常用车辆",@"车源"];
    for (int i = 0; i < arr.count; i++) {
        self.disButton = [[UIButton alloc]initWithFrame:CGRectMake(i * (WIDTH/arr.count),kMainTopHeight, kMainScreen_width/arr.count, GTFixHeightFlaot(25))];
        [self.disButton setTitle:arr[i] forState:UIControlStateNormal];
        [self.disButton addTarget:self action:@selector(disButtonClieck:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 0) {
            self.disButton.selected = YES;
            self.selectedBtn = self.disButton;
        }
        self.disButton.backgroundColor = [UIColor whiteColor];
        self.disButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.disButton setTitleColor:[UIColor colorWithRed:120/255.0 green:177/255.0 blue:235/255.0 alpha:1] forState:UIControlStateSelected];
        [self.disButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.disButton.tag = 100 + i;
        [self.view addSubview:self.disButton];
    }
    UILabel * labelLin = [[UILabel alloc]initWithFrame:CGRectMake( 0, self.disButton.bottom + 1 , kMainScreen_width, 1)];
    labelLin.backgroundColor = WGColor;
    [self.view addSubview:labelLin];
    self.viewGray = [[UIView alloc]initWithFrame:CGRectMake(0, self.disButton.bottom , kMainScreen_width/arr.count, 2)];
    self.viewGray.backgroundColor = [UIColor colorWithRed:120/255.0 green:177/255.0 blue:235/255.0 alpha:1];
    [self.view addSubview:self.viewGray];
    [self.view addSubview:self.vehicleTV];
}
-(void)createUItextField {
    self.placeLabale = [UILabel labelWithSize:[UIFont systemFontOfSize:12] withColor:[UIColor grayColor] withText:@"起始地"];
    self.placeLabale.textAlignment = NSTextAlignmentCenter;
    self.placeLabale.layer .borderColor = [UIColor grayColor].CGColor;
    self.placeLabale.layer .borderWidth = 1.0;
    [self.placeLabale addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
       
        
    }];
    
    UIImageView * jianTouImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"jiantou"]];
    self.destinationaLbale = [UILabel labelWithSize:[UIFont systemFontOfSize:12] withColor:[UIColor grayColor] withText:@"目的地"];
    [self.destinationaLbale addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        
        
    }];
    self.destinationaLbale.textAlignment = NSTextAlignmentCenter;
    self.destinationaLbale.layer .borderColor = [UIColor grayColor].CGColor;
    self.destinationaLbale.layer .borderWidth = 1.0;
    self.specificationLabale = [UILabel labelWithSize:[UIFont systemFontOfSize:12] withColor:[UIColor grayColor] withText:@"车长、车型"];
    [self.specificationLabale addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        
        
    }];
    self.specificationLabale.textAlignment = NSTextAlignmentCenter;
    self.specificationLabale.layer .borderColor = [UIColor grayColor].CGColor;
    self.specificationLabale.layer .borderWidth = 1.0;
     [self.headView addSubview:self.placeLabale];
     [self.headView addSubview:jianTouImage];
     [self.headView addSubview:self.destinationaLbale];
     [self.headView addSubview:self.specificationLabale];

    [self.placeLabale mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(GTFixWidthFlaot(20)));
        make.top.equalTo(@(GTFixHeightFlaot(10)));
        make.height.equalTo(@(GTFixHeightFlaot(15)));
        make.width.equalTo(@(GTFixWidthFlaot(50)));
    }];
    [jianTouImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.placeLabale.mas_right).offset(GTFixWidthFlaot(5));
        make.top.equalTo(@(GTFixHeightFlaot(13)));
        make.height.equalTo(@(GTFixHeightFlaot(10)));
        make.width.equalTo(@(GTFixWidthFlaot(30)));
    }];
    [self.destinationaLbale mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(jianTouImage.mas_right).offset(GTFixWidthFlaot(5));
        make.top.equalTo(@(GTFixHeightFlaot(10)));
        make.height.equalTo(@(GTFixHeightFlaot(15)));
        make.width.equalTo(@(GTFixWidthFlaot(50)));
    }];
    [self.specificationLabale mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(GTFixWidthFlaot(-20));
        make.top.equalTo(@(GTFixHeightFlaot(10)));
        make.height.equalTo(@(GTFixHeightFlaot(15)));
        make.width.equalTo(@(GTFixWidthFlaot(60)));
    }];
    
}
-(void)disButtonClieck:(UIButton *)sender {
    if (self.selectedBtn != sender) {
        self.selectedBtn.selected = NO;
        self.selectedBtn = sender;
    }
    self.selectedBtn.selected = YES;
    switch (sender.tag - 100) {
        case 0:{
            //
            [UIView animateWithDuration:.3 animations:^{
                self.viewGray.frame = CGRectMake(0, self.disButton.bottom, WIDTH/2 , 2);
                self.vehicleTV.hidden = NO;
                self.navRightBtn .hidden = NO;
                self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kMainScreen_width,GTFixHeightFlaot(1))];
                self.vehicleTV.tableHeaderView = self.headView;
            }];
        }
            break;
        default:{
            //车源
            [UIView animateWithDuration:.3 animations:^{
                self.viewGray.frame = CGRectMake(WIDTH/2, self.disButton.bottom, WIDTH/2 , 2);
                self.vehicleTV.hidden = NO;
                self.navRightBtn .hidden = YES;
                self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kMainScreen_width,GTFixHeightFlaot(33))];
                self.headView.backgroundColor = [UIColor whiteColor];
                [self createUItextField];
                self.vehicleTV.tableHeaderView = self.headView;
                
            }];
        }
            break;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    VehicleTVCell *cell=[tableView dequeueReusableCellWithIdentifier:@"VehicleTVCell"];
    if (!cell) {
        cell=[[VehicleTVCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"VehicleTVCell"];
    }
    cell.delegate = self;
    cell.indexPath = indexPath;
    return cell;
}
#pragma  mark -----cell代理
-(void)vehiclewithIndexPath:(NSIndexPath *)index withtype:(NSString *)type{
    if ([type isEqualToString:@"1"]) {
        ZFLog(@"打个电话");
    }else{
        ZFLog(@"你来吧");
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kMainScreen_width,GTFixHeightFlaot(15))];
        return self.headView;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return GTFixHeightFlaot(15);
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return GTFixHeightFlaot(70);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    VehicleDetailsVC * vc = [VehicleDetailsVC  new];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
